
#include "xm_log.h"


using namespace log4cplus;
using namespace log4cplus::helpers;

//log4cplus::Logger &glogger = log4cplus::Logger::getRoot();

//const LogLevel 	log4cplus::OFF_LOG_LEVEL = 60000
//The OFF_LOG_LEVEL LogLevel is used during configuration to turn off logging. More...
//
//const LogLevel 	log4cplus::FATAL_LOG_LEVEL = 50000
//The FATAL_LOG_LEVEL LogLevel designates very severe error events that will presumably lead the application to abort. More...
//
//const LogLevel 	log4cplus::ERROR_LOG_LEVEL = 40000
//The ERROR_LOG_LEVEL LogLevel designates error events that might still allow the application to continue running. More...
//
//const LogLevel 	log4cplus::WARN_LOG_LEVEL = 30000
//The WARN_LOG_LEVEL LogLevel designates potentially harmful situations. More...
//
//const LogLevel 	log4cplus::INFO_LOG_LEVEL = 20000
//The INFO_LOG_LEVEL LogLevel designates informational messages that highlight the progress of the application at coarse-grained level. More...
//
//const LogLevel 	log4cplus::DEBUG_LOG_LEVEL = 10000
//The DEBUG_LOG_LEVEL LogLevel designates fine-grained informational events that are most useful to debug an application. More...
//
//const LogLevel 	log4cplus::TRACE_LOG_LEVEL = 0
//The TRACE_LOG_LEVEL LogLevel is used to "trace" entry and exiting of methods. More...
//
//const LogLevel 	log4cplus::ALL_LOG_LEVEL = TRACE_LOG_LEVEL
//The ALL_LOG_LEVEL LogLevel is used during configuration to turn on all logging. More...
//
//const LogLevel 	log4cplus::NOT_SET_LOG_LEVEL = -1

static
void xm_log_default_config(){

    // see http://www.cppblog.com/api/archive/2011/04/02/143283.html
    
    SharedObjectPtr<Appender> _append (new ConsoleAppender());
    _append->setName(LOG4CPLUS_TEXT("append for test"));

    std::auto_ptr<Layout> _layout(new PatternLayout(LOG4CPLUS_TEXT("%D{%m/%d %H:%M:%S.%q} %-5p - %m %n")));
    _append->setLayout( _layout );
    
    Logger::getRoot().addAppender(_append);
    Logger::getRoot().setLogLevel(ERROR_LOG_LEVEL);
}

void xm_log_init(const char * config_file){
//    log4cplus::BasicConfigurator config;
//    config.configure();
//    //    glogger = log4cplus::Logger::getRoot();
    
    if(config_file && config_file[0] != '\0'){
        PropertyConfigurator::doConfigure( config_file );
    }else{
        xm_log_default_config();
    }

    
}
